package com.bawei.lib_common.jpush.receiver

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import cn.jpush.android.api.JPushInterface
import com.bawei.lib_common.base.utils.LoggerUtils


/**
 *作者：lxy
 *功能:
 *时间：2025/5/27
 */
class MyReceiver:BroadcastReceiver() {

    companion object{
        const val TAG = "MyReceiver"
    }
    override fun onReceive(context: Context?, intent: Intent?) {
        //数据
        val bundle = intent?.extras

        if (intent?.action == JPushInterface.ACTION_REGISTRATION_ID){ // 注册成功
            val registrationId = bundle?.getString(JPushInterface.EXTRA_REGISTRATION_ID) //注册id--》服务器绑定
            LoggerUtils.d(TAG,"注册成功:  $registrationId")

        }else if(intent?.action == JPushInterface.ACTION_MESSAGE_RECEIVED){//透传消息
            val message = bundle?.getString(JPushInterface.EXTRA_MESSAGE)
            LoggerUtils.d(TAG,"透传消息:  $message")

        }else if(intent?.action == JPushInterface.ACTION_NOTIFICATION_RECEIVED){//通知消息
            val title = bundle?.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE)
            val content = bundle?.getString(JPushInterface.EXTRA_ALERT)
            LoggerUtils.d(TAG,"通知消息:  $title  $content")
        } else if (intent?.action == JPushInterface.ACTION_NOTIFICATION_CLICK_ACTION){//打开通知
            val title = bundle?.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE)
            val content = bundle?.getString(JPushInterface.EXTRA_ALERT)
            LoggerUtils.d(TAG,"打开通知:  $title  $content")

        }
    }
}